#include "../include/alphadog_monitor/graph_setting.h"
#include "ui_graph_setting.h"
#include <QSettings>
#include <QLineEdit>

graph_setting::graph_setting(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::graph_setting)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);

    // 初始化
    initWidget();
}

graph_setting::~graph_setting()
{
    delete ui;
}

void graph_setting::initWidget(void){
    // 最小化和关闭
    connect(ui->btnWinClose, &QPushButton::clicked, [=]() { this->close(); });
    connect(ui->btnWinMin, &QPushButton::clicked, [=]() { this->showMinimized(); });

    // 读取话题
    QSettings set("alphadog_monitor","settings");
    ui->lineEditTopic->setText(set.value("graph/data", "/alphadog_monitor/graph_data").toString());

    // 关联回车
    connect(ui->lineEditTopic, &QLineEdit::returnPressed, [=](){
        QSettings set("alphadog_monitor","settings");
        QString data = ui->lineEditTopic->text();
        set.setValue("graph/data", data);
    });
}
